<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Product_ask extends CIC_A_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$data	= $this->get_product_ask();
		$this->load->view('admin/product_ask/index',$data);
	}
	
	function get_product_ask()
	{
		$url = site_url('admin/product_ask/index?');
		$data['page']	 = $this->page($url, $this->cic_model->get_total_rows('product_ask'), $this->per_page,TRUE);
		$data['product_ask'] = $this->cic_model->get_all('product_ask','',array('ask_create_time','desc'),$this->per_page,$this->input->get('per_page'));
		return $data;
	}

	function delete_product_ask()
	{
		echo $this->cic_model->delete('product_ask',array('ask_id'=>$this->input->post('ask_id')));
	}

	function ask_reply()
	{
		$product_ask = $this->cic_model->get_one('product_ask',array('ask_id'=>$this->uri->segment(4)));
		if($product_ask->ask_status == '0')
			$this->cic_model->update('product_ask',array('ask_status'=>1),array('ask_id'=>$this->uri->segment(4)));
		$data['product_ask']	= $this->cic_model->get_one('product_ask',array('ask_id'=>$this->uri->segment(4)),array('ask_create_time','desc'));
		$this->load->view('admin/product_ask/ask_reply',$data);
	}

	function reply_ask()
	{
		$this->validate('reply_ask', 'admin/product_ask/ask_reply/'.$this->uri->segment(4));
		$data = array(
				'ask_status'		=> 2,
				'ask_reply_content'	=> $this->input->post('ask_reply_content'),
				'ask_reply_time'	=> time(),
		);
		if($this->cic_model->update('product_ask',$data,array('ask_id'=>$this->uri->segment(4))))
		{
			$this->message->msg('回复成功！',site_url('admin/product_ask/index'));
		}
	}

	function shenhe()
	{
		if($this->cic_model->update('product_ask',array('ask_shenhe'=>1),array('ask_id'=>$this->input->post('ask_id'))))
		{
			echo 1;
		}
	}
}